<?php
$ro=file_get_contents('php://input'); //得到前端的json文件
$user=json_decode($ro,true);   //转变成php数组
$schoolNumber=$user['schoolNumber'];   //取出对应数据
$bookNumber=$user['bookNumber'];

//连接数据库
$link=new mysqli('127.0.0.1','root','root','books_manage_system','3306');
if($link->connect_error){
    die('连接失败'.$link->connect_error);
}else{
    //连接成功，设置编码格式
    mysqli_set_charset($link,'utf8');
    $link->query('SET NAMES UTF8');

    //存储数据
    $result=array();
    $result['user']=array();
    $result['book']=array();

    if($schoolNumber&&$bookNumber){
        $sql1="select * from users where schoolNumber='$schoolNumber'";
        $sql2="select * from books where booknumber='$bookNumber'";
        $re1=$link->query($sql1);
        $re2=$link->query($sql2);
        $num1=mysqli_num_rows($re1);
        $num2=mysqli_num_rows($re2);

        //用户查询
        if($num1>0){
            $row1=mysqli_fetch_assoc($re1);
            array_push($result['user'],$row1);
            $result['status_user']='success';
            $result['message']='获取成功';
        }else{
            $result['status_user']='fail';
            $result['message_user']='查无此人';
        }

        //书籍查询
        if($num2>0){
            $row2=mysqli_fetch_assoc($re2);
            //判断此书是否为借阅状态
            if(($row2['status']=='0'&&$row2['dstatus']=='1') || ($row2['status']=='1'&&$row2['dstatus']=='1')){
                array_push($result['book'],$row2);
                $result['status_book']='success';
                $result['message']='获取成功';
            }else{
                $result['status_book']='fail';
                $result['message_book']='借阅失败';
            }
        }else{
            $result['status_book']='fail';
            $result['message_book']='查无此书';
        }
    }
mysqli_free_result($re1); //释放结果集
mysqli_free_result($re2); //释放结果集
//关闭数据库
$link->close();
die(json_encode($result));
}
?>